using Microsoft.AspNetCore.Mvc;
using Yi.Web.Dto;
using Yi.Web.Model;
namespace Yi.Web.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class BlogController(ZaoDbContext db) :ControllerBase{
        private readonly ZaoDbContext db=db;
        [HttpGet]
        public IActionResult Get(){
            var list =db.Blogs.ToList();
            return Ok(new {Code=1000,Data=list,Msg="查询列表成功"});
        }
        
        [HttpPost]
        public IActionResult Post(BlogAddDto dto){
            var blog=new Blog{
                Titel=dto.Titel,
                Author=dto.Author,
                Content=dto.Content
            };
            db.Add(blog);
            db.SaveChanges();
            return Ok(new {Code=1000,Data=new BlogResultDto(blog.Titel,blog.Author,blog.Content),Msg="新增成功"});
        }
    }
}